function plusOne(digits: number[]): number[] {
    let index = digits.length - 1;
    const start_with_nine = digits[0] === 9;


    while (index >= 0) {
        if (digits[index] === 9) {
            digits[index] = 0;
            index--;
        } else {
            digits[index]++;
            break;
        }
    }
    if (start_with_nine && digits[0] !== 9) {
        digits.unshift(1)
    }

    return digits;
};